package com.xrui;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Random;

public class xmlwriter {
    public static Document getDoc() throws UnsupportedEncodingException {
        Document doc = DocumentHelper.createDocument();

        Element acountE = doc.addElement("acount");
        acountE.addComment("中国");
        Element rolesE = acountE.addElement("roles");
        Element usersE = acountE.addElement("users");



        return doc;
    }
    public static int createXml(String file){

        int returnValue = 0;
        Document doc = null;
        XMLWriter writer;
        try {
            doc = getDoc();
            File fileT = new File(file);
            if(!fileT.createNewFile()){
                fileT.delete();
                fileT = new File(file);
            }

            writer = new XMLWriter(new FileOutputStream(fileT));
            writer.write(doc);
            writer.close();
            returnValue = 1;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return returnValue;
    }
}
